package com.ys.peony.utils;

import android.app.ActivityManager;
import android.content.Context;

import com.ys.peony.R;

import java.util.List;

/**
 * describe:动画工具类
 * author:zhangcong
 * date:2017/5/6 22:10
 */
public class AnimUtils {


    /**
     * 动画效果,进入
     */
    public static void inAnim() {
        leftInTranslateAnim();
    }

    /**
     * 动画效果,退出
     */
    public static void outAnim() {
        rightOutTranslateAnim();
    }

    /**
     * 左右移动动画效果:左进
     */
    public static void leftInTranslateAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
    }

    /**
     * 左右移动动画效果:右出
     */
    public static void rightOutTranslateAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
    }

    /**
     * 上下移动动画效果:上进
     */
    public static void upInTranslateAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.in_from_top, R.anim.push_static);
    }

    /**
     * @Description: 从下进入
     */
    public static void bottomInTranslateAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.in_from_bottom, R.anim.push_static);
    }

    /**
     * 上下移动动画效果:下出
     */
    public static void downOutTranslateAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.push_static, R.anim.push_down_out);
    }

    /**
     * 淡入淡出动画效果
     */
    public static void fadeAlphaAnim() {
        AppUtils.getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    }

    /**
     * Check service state
     *
     * @param context
     * @param className
     * @return
     */
    public static boolean isServiceRunning(Context context, String className) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> list = am.getRunningServices(30);
        for (ActivityManager.RunningServiceInfo info : list) {
            if (info.service.getClassName().equals(className)) {
                return true;
            }
        }
        return false;
    }


}
